<?PHP
session_start();

// Capturing errors to report back.
include_once('classes/error.class.php');
$errors = new errors();


// Config file for all of Mullet.
require_once('includes/configuration.php');


// Connect to Mullet database.
$mul_db = mysql_connect($mConfig['mul_server'], $mConfig['mul_user'], $mConfig['mul_pass'])
	or die('Could not establish connection to Mullet database.');
mysql_select_db($mConfig['mul_name'], $mul_db) or die('Could not select Mullet database.');


// Connect to SMF database.
$smf_db = mysql_connect($mConfig['smf_server'], $mConfig['smf_user'], $mConfig['smf_pass'])
	or die('Could not establish connection to SMF database.');
mysql_select_db($mConfig['smf_name'], $smf_db) or die('Could not select SMF database.');


// Include class files and functions, sans error class, which is already loaded.
foreach($mConfig['includes'] as $file) require_once($file);





// Begin page.
echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
	"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" version="-//W3C//DTD XHTML 1.1//EN" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
	<title>Shinsei Events</title>

	<script src="includes/functions.js" type="text/javascript"></script>
	<link href="includes/style.css" rel="stylesheet" type="text/css" />
	<link href="includes/pro_dropline.css" rel="stylesheet" type="text/css" />
	<!--[if IE]>
	<link href="includes/pro_dropline_ie.css" rel="stylesheet" type="text/css" />
	<![endif]-->
	<link rel="alternate" type="application/rss+xml" title="Raids" href="mullet.rss.php" />
</head>
<body>




<div id="header">
	<img src="images/mullet.jpg" width="330" height="150" alt="MULLET" />
</div>





<div class="nav">
	<div class="table">


	<!-- Forums -->
	<ul class="select"><li><a href="../"><b>Forums</b>
	</a></li></ul>


	<!-- Mullet Home -->
	<ul class="select"><li><a href="index.php"><b>Mullet Home</b>
	</a></li></ul>


	<!-- My Characters -->
	<ul class="select"><li><a href="http://www.shinsei-guild.org/index.php?action=profile;u='.$_SESSION['mul_user_id'].';sa=wowchar"><b>My Characters</b>
	</a></li></ul>


	<!-- Read Me -->
	<ul class="select"><li><a href="index.php?page=readme"><b>Read Me</b>
	</a></li></ul>


	<!-- Administration -->';


	if ($_SESSION['mul_permission'] == CLASS_LEADER or $_SESSION['mul_permission'] == OFFICER)
	{
		echo '
	<ul class="select"><li><a href="index.php?page=admin"><b>Administration</b><!--[if IE 7]><!--></a><!--<![endif]-->
	<!--[if lte IE 6]><table><tr><td><![endif]-->
	<div class="select_sub">
		<ul class="sub">
			<li><a href="index.php?page=admin&amp;action=add">Add Event</a></li>
			<li><a href="index.php?page=admin&amp;action=list">List / Edit Events</a></li>
			<li><a href="index.php?page=admin&amp;action=template">Templates</a></li>
			<li><a href="index.php?page=admin&amp;action=history">Event History</a></li>
		</ul>
	</div>
	<!--[if lte IE 6]></td></tr></table></a><![endif]-->
	</li>
	</ul>';
	}

echo '
	</div>
</div>


<div id="body">';





// If the user is logged in, load the requested page, or the default.
if ($_SESSION['mul_username'])
{
	// New instance of user that is logged in.
	$user = new subscriber($mul_db, $smf_db);
	$user->getUsersCharacters($_SESSION['mul_user_id']);


	// Check to make sure they have characters in their forum profile.
	if (count($user->characters) == 0)
		$errors->addError('index', 'No characters defined in forum profile.');





	// Display all notices and error messages collected.
	if ($errors->error_count > 0)
	{
		echo '<div class="notice">
		<p>Notices:</p>';

		foreach ($errors->error_messages as $source)
		{
			for ($i = 0; $i < count($source); $i++)
				echo '<p class="error">'.$source[$i].'</p>';
		}

		echo '</div>';
	}





	if (isset($_GET['page']) and file_exists('pages/'.$_GET['page'].'.php')) include('pages/'.$_GET['page'].'.php');
	else include('pages/events.php');
}


// The user is not logged in, display a login form.
else
{
	echo '
<form method="post" action="../index.php?action=login2" id="smf_login" class="login">
<label for="user">Username:</label>
<input name="user" maxlength="30" class="inputBox" value="" />

<label for="passwrd">Password:</label>
<input name="passwrd" value="" type="password" />

<input type="submit" value="Submit" />
</form>';
}





echo '
</div>


</body>
</html>';

?>
